<%@page contentType="text/html; charset=utf-8"%>
<div id="message" style="z-index:100;position:absolute;bottom:0;display:none;right:0;">
	<div id="backimage" style="background:url(/images/tips_bg.jpg);width:256px;height:184px;">
	    <div style="width:100%;height:25px;overflow:hidden;" id="messageTool">
	        <div style="padding:3px 0 0 30px;width:100px;line-height:20px;text-align:center;overflow:hidden;position:absolute;font-size:14px;" id="msgtitle">您有新消息</div>
	        	<span id="message_close" style="right:10px;width:16px;text-align:center;cursor:pointer;position:absolute;">&nbsp;</span>
	        <div style="clear:both;"></div>
	    </div>
	    <div id="message_content" style="margin:0 5px 0 5px;padding:10px 0 10px 5px;width:239px;height:100px;text-align:left;overflow:auto; scrollbar-face-color: #F8EAE9;scrollbar-shadow-color:#EF8883; scrollbar-highlight-color:#EF8883; scrollbar-3dlight-color: #EF8883;scrollbar-darkshadow-color: #EF8883;scrollbar-track-color:#AB423D; scrollbar-arrow-color: #AB423D;">
	    	<table width="100%">
	    		<tbody id="msgTbl">
		        </tbody>
		    </table>
	    </div>
	    <div style="padding:14px 10px 0px 0px;text-align:right;FONT-SIZE: 12px;">
	    	<A href='#' onClick='setAllMsgRead();' style='color:#003399;text-decoration:none;' hidefocus=false>全部设为已读</A>
	    	&nbsp;&nbsp;
	    	<A href='#' onClick='showAllMsg();' style='color:#003399;text-decoration:none;' hidefocus=false>查看</A>
	    </div>
	    <div id="soundObj" style="display:none"></div>
    </div>
</div>
<script language="javascript">
	var maxMsgId=0;
	var interval=${enterpriseInfo.msgInterval};
	if(interval<=0){
		interval=1;
	}
	function checkMsg(){
		var xmlHttp=createXMLHttpRequest();
		xmlHttp.open("GET", "/LeftMessage.ihtm",true);//true表示异步执行
		xmlHttp.onreadystatechange = function(){
			if (xmlHttp.readyState == 4) {
	      		if (xmlHttp.status == 200) {
	      			var divObj=document.getElementById("message");
	      			var tblObj=document.getElementById("msgTbl");
	      			//先清除(不能用判断增量然后insert,因为无法知道中间的某一条是否在其他地方被读了)
	      			var len=tblObj.rows.length;
	      			try{
	      				for(var i=0;i<len;i++){
	      					tblObj.deleteRow(0);
	      				}
      				}catch(ex){}
      				
      				var playSound=false;
	      			var data=xmlHttp.responseXML.getElementsByTagName("msg");
	      			if(data.length>0){
	      				for(var i=0;i<data.length;i++){
		      				var id=getNodeValue(data[i],"id");//NND,不能用var id=getNodeValue(data[i].childNodes[0])这种方式(在chrome和safari里childNodes长度不一样)
		      				var sender=getNodeValue(data[i],"sender");
		      				var title=getNodeValue(data[i],"title");
		      				
		      				if(i==0 && maxMsgId<id-0){
		      					playSound=true;
		      					maxMsgId=id-0;
		      				}
		      				
		      				var tr=tblObj.insertRow(i);
		      				tr.setAttribute("index",id);
		      				var td=document.createElement("td");
		      				td.style.height="20px";
							td.style.fontSize="12px";
		      				td.innerHTML="<FONT color=#ff0000>["+sender+"]</FONT>：<FONT color=#ff0000><A href='#' onClick='showPopMsg("+id+");' style='color:#003399;text-decoration:none;' hidefocus=false>"+title+"</A></FONT>";
		      				tr.appendChild(td);
		      			}
		      			if(divObj.style.display=="none"){
		      				playSound=true;
		      				$("#message").Show(256,184);//这个高度要跟底图匹配
		      			}
		      			if(playSound){
		      				document.getElementById("soundObj").innerHTML="<embed src='/images/msg.wav' autostart='true' hidden='true' loop='false'>";
		      				playSound=false;
		      			}
	      			}else{
	      				if(divObj.style.display!="none"){
	      					$("#message_close").click();
	      				}
	      			}
	      		}
	      	}
	    }
	    xmlHttp.send(null);
	    
	    setTimeout("checkMsg()",1000*60*interval);
	}
	function getNodeValue(node,tagName){
		var children=node.childNodes;
		for(var j=0;j<children.length;j++){
			if(children[j].tagName==tagName){
				return children[j].firstChild.data
			}
		}
		return "";
	}
	function showPopMsg(id){
		var tblObj=document.getElementById("msgTbl");
		try{
			for(var i=0;i<tblObj.rows.length;i++){
				if(tblObj.rows[i].getAttribute("index")==id){
					tblObj.deleteRow(i);
					break;
				}
			}
		}catch(ex){}
		if(tblObj.rows.length==0){
			$("#message_close").click();
		}
		showMessageInfo(id);
	}
	function setAllMsgRead(){
		var tblObj=document.getElementById("msgTbl");
		var len=tblObj.rows.length;
		try{
			for(var i=0;i<len;i++){
				tblObj.deleteRow(0);
			}
		}catch(ex){}
		
		$("#message_close").click();
		$.post("/MessageReadFlagUpdate.ihtm",{},function(data,status){
			
		});
	}
	function showAllMsg(){
		$("#message_close").click();
		showWin(1024,600,'/message/Main.ihtm');
	}
	
	$(document).ready(function() {
		checkMsg();
	});
</script>